package Leetcode;

import tree.TreeNode;

public class pathSum {
    public int pathSum(TreeNode root, int targetSum) {
        if (root == null){
            return 0;
        }
        return getPathSum(root, targetSum)
        +pathSum(root.left, targetSum)
        +pathSum(root.right, targetSum);
    }
    public int getPathSum(TreeNode root, long sum){
        if (root == null){
            return 0;
        }
        int count = 0;
        if (root.val == sum){
            count++;
        }
        count += getPathSum(root.left, sum - root.val);
        count += getPathSum(root.right, sum - root.val);
        return count;
    }
}
